
USE [bdSEA]

GO

IF OBJECT_ID('sSEA_ConsultarCorreosPorObjetoyFormulario') IS NOT NULL
	DROP PROCEDURE sSEA_ConsultarCorreosPorObjetoyFormulario
GO
CREATE PROCEDURE sSEA_ConsultarCorreosPorObjetoyFormulario
@iIdFormulario	INT,
@iCodigoObjeto	INT
AS
BEGIN
	SET NOCOUNT ON
	SET DATEFORMAT DMY

	SELECT 
		LTRIM(RTRIM(usu.vNombreUsuario)) AS [Usuario], 
		LTRIM(RTRIM(ale.vAsunto))		 AS [Asunto], 
		LTRIM(RTRIM(ale.vMensaje))		 AS [Mensaje]
	FROM 
		[bdSEA].[dbo].[tSEA_Usuario] usu 
		INNER JOIN [bdGEN].[dbo].[tGEN_GrupoCargo] gca ON(usu.iIdCargo = gca.iCodigoCargo)
		INNER JOIN [bdGEN].[dbo].[tGEN_AlertaGrupo] alg ON(alg.iIdGrupo = gca.iIdGrupo)
		INNER JOIN [bdGEN].[dbo].[tGEN_Alerta] ale ON(ale.iIdAlerta = alg.iIdAlerta)
		INNER JOIN [bdSEA].[dbo].[tSEA_FormularioObjeto] fob ON(fob.iIdAlerta = ale.iIdAlerta)
	WHERE
		ale.bEliminado = 0
		AND fob.bAlerta = 1
		AND fob.bEliminado = 0
		AND fob.iIdFormulario = @iIdFormulario
		AND fob.iCodigoObjeto = @iCodigoObjeto		
	SET NOCOUNT OFF
END

GO

EXEC sSEA_ConsultarCorreosPorObjetoyFormulario 318, 4


--SELECT * FROM [bdSEA].[dbo].[tSEA_Formulario]
--SELECT * FROM [bdSEA].[dbo].[tSEA_FormularioObjeto]
--SELECT * FROM [bdSEA].[dbo].[tSEA_Descripcion] WHERE iCodigoTabla = 3 AND ICODIGOESTADO = 1 AND ICODIGOELEMENTO <> 0

--SELECT * FROM [bdGEN].[dbo].[tGEN_Alerta]
--SELECT * FROM [bdGEN].[dbo].[tGEN_AlertaGrupo]
----SELECT * FROM [bdGEN].[dbo].[tGEN_Grupo]
--SELECT * FROM [bdGEN].[dbo].[tGEN_GrupoCargo]
--SELECT * FROM [bdSEA].[dbo].[tSEA_Descripcion] WHERE iCodigoTabla = 2 AND ICODIGOESTADO = 1 AND iCodigoElemento <> 0
--SELECT * FROM [bdSEA].[dbo].[tSEA_Usuario] WHERE iIdCargo = 1



--SELECT * FROM [dbo].[tSEA_Perfil]
